package com.swhysc.information.repository;


import com.swhysc.information.entity.InformationDataDirectoryEx;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

/**
 * 资讯目录jpa
 */
public interface InformationDataDirExRepository extends JpaRepository<InformationDataDirectoryEx, String>, QuerydslPredicateExecutor<InformationDataDirectoryEx> {

    @Query(value = "select  max(o.LEVEL_CODE) as MAXCHILDREN from INFORMATION_DATA_DIRECTORY_EX o where o.PARENT_ID =:parentId", nativeQuery = true)
    String getMaxChilren(@Param("parentId") String parentId);


    /**
     * 根据类型获取对应的数据
     * @param type 类型
     * @return
     */
    List<InformationDataDirectoryEx> findAllByType(Integer type);


    /**
     * 批量删除
     * @param ids id集合
     */
    @Transactional
    Integer deleteAllByIdIn(List<String> ids);


    List<InformationDataDirectoryEx> findInformationDataDirectorysByName(String name);


    InformationDataDirectoryEx findInformationDataDirectoryByName(String name);

    List<InformationDataDirectoryEx> findByParentId(String pid);

    List<InformationDataDirectoryEx> findByParentIdOrderByLevelAscSortAscUpdateTimeDescNameAsc(String pid);

    List<InformationDataDirectoryEx> findAllByIdInOrderBySortAsc(Set<String> ids);

    List<InformationDataDirectoryEx> findByLevelOrderByLevelAscSortAscUpdateTimeDescNameAsc(String level);
}
